<? 
	include('base.php');
	User::protect();
	include_class('general_media');
	include_class('m2');
	$media = new Media();
	$ma = MediaArea::get($_REQUEST['id']);
	
	if ($_GET['task'] == 'update' && !db::isError($ma)) {
		$res = $ma->updatePreferences($_POST);
		if (!db::isError($res)) {
			header('Location: media_preferences.php?id=' . $_GET['id']);
		}
	}
	
	$page_title = 'Media Preferences';
	$stylesheet = 'popup.css';
	include('layout/header_popup.php'); 
	
if (!db::isError($ma)) {
	if (User::isAdmin()) {	
		if ($_GET['task'] == 'edit') { ?>
	
		<h1>edit media area</h1>
		<div class="inset">
			<form id="edit_entry" action="<?=$PHP_SELF?>?task=update&amp;id=<?=$_GET['id']?>" method="post">
			<table border="0" cellspacing="0" cellpadding="0" class="edit-form">
			<tr>
				<td colspan="2"><strong>Title:</strong><br/><?=$ma->getTitle()?></td>
			</tr>
			<tr>
				<td colspan="2"><strong>Title:</strong><br/>
				<?=$ma->getDescription()?></td>	
			</tr>
			<tr>
				<td width="50%"><strong>Image&nbsp;Max&nbsp;Width:</strong><br/>
				<input type="text" class="text" name="image_max_width" value="<?=$ma->getMaxWidth()?>"></td>
				<td width="50%"><strong>Image&nbsp;Max&nbsp;Height:</strong><br/>
				<input type="text" class="text" name="image_max_height" value="<?=$ma->getMaxHeight()?>"></td>
			</tr>
			<tr>
				<td width="50%"><strong>Thumbnail Max&nbsp;Width:</strong><br/>
				<input type="text" class="text" name="image_max_thumbnail_width" value="<?=$ma->getMaxThumbnailWidth()?>"></td>
				<td width="50%"><strong>Thumbnail&nbsp;Max&nbsp;Height:</strong><br/>
				<input type="text" class="text" name="image_max_thumbnail_height" value="<?=$ma->getMaxThumbnailHeight()?>"></td>
			</tr>
			</table>
			<div class="edit-form">
				<input type="submit" value="Update Area Preferences" name="submit" class="button">
				<input type="submit" value="Exit Without Updating" name="return" onclick="location.href='<?=$PHP_SELF?>?id=<?=$_GET['id']?>';return false" class="button">
			</div>
			</div>
		
		<? } else { ?>

			<h1>media area</h1>
			<div class="inset">
				<h2><?=$ma->getTitle()?></h2><br>
				<b>Description:</b>
				<? if ($ma->getDescription()) {
					echo($ma->getDescription());
				} else {
					echo('None');
				} ?>
				<br><br>
				<b>Image Max Width:</b> <?=$ma->getMaxWidth()?><br>
				<b>Image Max Height:</b> <?=$ma->getMaxHeight()?><br>
				<b>Image Max Thumbnail Width:</b> <?=$ma->getMaxThumbnailWidth()?><br>
				<b>Image Max Thumbnail Height:</b> <?=$ma->getMaxThumbnailHeight()?><br>
			
			<br>
			<form name="entry_status" method="get">
				<input type="submit" name="" value="Edit Entry" onclick="location.href='<?=$PHP_SELF?>?task=edit&id=<?=$_GET['id']?>';return false" class="button">
				<input type="submit" value="Exit and Close Window" name="" onclick="javascript:top.close(); return false" class="button">
			</form>
			
			</div>
	
		
		<? } ?>
		
	
	<? } else {
	
		Error::outputDialog(null, null, 'Only an administrator may set media preferences.');
		
	}
	
} else {

	$ma->outputDialog(null, null);

} ?>

<? include('layout/footer_popup.php'); ?>
